<template>
  <div style="width:98%;height:100%;margin:0 auto;margin-top:10px">
    <el-card class="box-card">
      <!-- 表头 -->
      <div slot="header" class="clearfix">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/home/deploy' }">协议列表</el-breadcrumb-item>
          <el-breadcrumb-item>用户协议</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <!--新增修改用户协议 -->
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="协议标题" prop="agreementTitle">
          <el-input v-model="ruleForm.agreementTitle" style="width:300px" disabled></el-input>
        </el-form-item>

        <el-form-item label="协议类型" prop="agreementType">
          <el-select v-model="ruleForm.agreementType" placeholder="请选择协议类型" style="width:300px" disabled>
            <el-option label="关于我们" :value="1"></el-option>
            <el-option label="用户协议" :value="2"></el-option>
            <el-option label="隐私协议" :value="3"></el-option>
            <el-option label="游戏协议" :value="4"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="协议内容" prop="agreementContent">
          <el-input
            type="textarea"
            v-model="ruleForm.agreementContent"
          :autosize="{ minRows: 2, maxRows: 20}"
            style="width:400px"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
          <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
          <el-button @click="resetForm()">返回</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        agreementTitle: "",
        agreementType: "",
        agreementContent: ""
      },
      rules: {
        agreementTitle: [
          { required: true, message: "请输入隐私协议标题", trigger: "blur" }
        ],
        agreementType: [
          { required: true, message: "请选择协议的类型", trigger: "change" }
        ],
        agreementContent: [
          { required: true, message: "请填写协议的内容", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    setTimeout(() => {
      // 获取管理员id
      console.log("获取menuId", this.$route.query.agreementId);
      if (this.$route.query.agreementId) {
        // 获取管理员详情
        this.$http.article
          .getUserDeployDetails({
            yj_agreementId: this.$route.query.agreementId
          })
          .then(res => {
            console.log("获取用户详情信息", res);
            this.ruleForm = res.result; //回显原数据
            this.ruleForm.agreementType = parseInt(res.result.agreementType);
            // this.fileList.push({ url: res.result.adminHeadImg }); //回显照片
          });
      }
    });
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          // 判断是否有用户Id
          if (this.$route.query.agreementId) {
            this.$http.article.updateUserdeploy(this.ruleForm).then(res => {
              console.log("测试新增协议内容", res);
              if (res.code == 200) {
                this.$message.success(res.msg);
                this.$router.push("/home/deploy");
              }
            });
          } else {
            this.$http.article.updateUserdeploy(this.ruleForm).then(res => {
              console.log("测试新增协议内容", res);
              if (res.code == 200) {
                this.$message.success(res.msg);
                this.$router.push("/home/deploy");
              }
            });
          }

          console.log("ruleForm", this.ruleForm);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // resetForm(formName) {
    //   this.$refs[formName].resetFields();
    // }
    resetForm() {
  this.$router.push("/home/deploy");
    }
  }
};
</script>

<style lang="scss" scoped>
// .el-input {
//   width: 300px;
// }
</style>